package cn.exrick.xboot.modules.commonlyUsed.controller;

import cn.exrick.xboot.common.utils.ResultUtil;
import cn.exrick.xboot.common.vo.Result;
import cn.exrick.xboot.modules.commonlyUsed.dto.CommonlyDTO;
import cn.exrick.xboot.modules.commonlyUsed.dto.CommonlyVO;
import cn.exrick.xboot.modules.commonlyUsed.entity.UserCommonly;
import cn.exrick.xboot.modules.commonlyUsed.service.IUserCommonlyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@Api(description = "个人常用功能管理")
@RequestMapping("/xboot/userCommonly")
@Transactional
public class UserCommonlyController {

    @Autowired
    private IUserCommonlyService userCommonlyService;

    @RequestMapping(value = "/getByUser", method = RequestMethod.POST)
    @ApiOperation(value = "获取登录用户的常用功能")
    public Result<List<CommonlyVO>> getAll(@RequestBody CommonlyDTO commonlyDTO) {
        List<CommonlyVO> list = userCommonlyService.userCommonlyList(commonlyDTO);
        return new ResultUtil<List<CommonlyVO>>().setData(list);
    }

    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    @ApiOperation(value = "保存登录用户的常用功能")
    public Result<UserCommonly> saveOrUpdate(@RequestBody CommonlyDTO commonlyDTO) {

        if (userCommonlyService.InsertCommonly(commonlyDTO)) {
            return new ResultUtil<UserCommonly>().setSuccessMsg("操作成功");
        }
        return new ResultUtil<UserCommonly>().setErrorMsg("操作失败");
    }

}
